/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.ruchin.tek.employees.json;

import com.google.gson.*;
import java.lang.reflect.Type;
import ru.ruchin.tek.employees.data.Department;

/**
 *
 * @author yruchin
 */
public class DepartmentListGsonSerializer implements JsonSerializer<Department[]> {
    @Override
    public JsonElement serialize(Department[] deps, Type type, JsonSerializationContext jsc) {
        JsonObject rootJo = new JsonObject();
        
        rootJo.addProperty("displayName", "Organization");
        
        JsonArray ja = new JsonArray();
        
        for (Department d : deps) {
            ja.add(jsc.serialize(d));
        }

        rootJo.add("children", ja);
        
        return rootJo;
    }
}
